
import dbo

#print(rules.rules_dict)

def identify(cond):
    result="不认识"
    for item in dbo.get_rules_all:
        if item['is_use']==0 and check_rule(item['conditions'],cond)==1 :
            if item['is_temp']==0 :
                result=item['result']
            else:
                item['is_use']=1
                cond.append(item['result'])
            print_tmp(item)
    return result

def check_rule(rule_cond,cond):
    rc_len=len(rule_cond)
    cd_len=len(cond)
    for rc_item in rule_cond:
        j=0
        for cd_item in cond:
            print("cd_item=={}".format(rc_item['id']),end=",")
            print("cd_item=={}".format(cd_item))
            if rc_item['id'] == cd_item:
                break
            j+=1
        if j>=cd_len:
            return 0
    return 1

def print_tmp(rules):
    str=' +  '.join(rules['conditions'])
    str=str+' ---->'+rules['result']
    print(str)
    return str

test_cond=['体型小','有轮子','两个轮']

result=identify(test_cond)
print("识别结果：{}".format(result))
